﻿using System.Collections.Generic;
using System.Runtime.Serialization;
using GMME.Util;
using UnityEngine;
using UnityEngine.Scripting;

namespace GMME.Model.Rtm.Req
{
    [DataContract]
    public class PublishRtmChannelMessageReq : RtmMessageContent
    {
        /**
         * 开发者传入的频道Id
         */
        [DataMember(Name = "channelId")]
        [Preserve]
        public string ChannelId { get; set; }

        /**
         * 频道内的指定玩家接收
         */
        [DataMember(Name = "receivers")]
        [Preserve]
        public List<string> Receivers { get; set; }

        /**
         * 是否缓存该消息
         */
        [DataMember(Name = "isAllowCacheMsg")]
        [Preserve]
        public bool IsAllowCacheMsg { get; set; }

        /**
         * 是否内容识别
         */
        [DataMember(Name = "isContentIdentify")]
        [Preserve]
        public bool IsContentIdentify { get; set; }

        /**
         * 是否广告识别
         */
        [DataMember(Name = "isAdsIdentify")]
        [Preserve]
        public bool IsAdsIdentify { get; set; }

#if UNITY_ANDROID
        public static AndroidJavaObject ConvertPublishRtmChannelMessageReq(PublishRtmChannelMessageReq req)
        {
            var androidJavaObject =
                new AndroidJavaObject("com.huawei.game.gmme.model.rtm.PublishRtmChannelMessageReq");

            androidJavaObject.Set("messageType", req.MessageType);
            androidJavaObject.Set("messageString", req.MessageString);
            if (req.MessageType == 2)
            {
                req.MessageString = "";
                TransferUtil.CsharpArrayToJavaArray(androidJavaObject, req.MessageBytes, "setMessageBytes");
            }

            androidJavaObject.Set("channelId", req.ChannelId);
            androidJavaObject.Set("receivers", TransferUtil.CsharpListToJavaList(req.Receivers));
            androidJavaObject.Set("isAllowCacheMsg", req.IsAllowCacheMsg);
            androidJavaObject.Set("isContentIdentify", req.IsContentIdentify);
            androidJavaObject.Set("isAdsIdentify", req.IsAdsIdentify);
            return androidJavaObject;
        }
#endif
    }
}